package com.zry.fertilizer.ui.activity

import android.content.Intent
import android.view.View
import com.zry.fertilizer.R
import com.zry.fertilizer.been.OutStock
import com.zry.fertilizer.been.OutStockInfo
import com.zry.fertilizer.been.ResultBean
import com.zry.fertilizer.databinding.ActivityOutTreasuryInfoBinding
import com.zry.fertilizer.retrofit.HttpServer
import com.zry.fertilizer.retrofit.ShowUserView
import com.zry.fertilizer.ui.base.BaseActivity
import kotlinx.android.synthetic.main.activity_out_treasury_info.*
import kotlinx.android.synthetic.main.common_title.*
import java.lang.Exception

class OutTreasuryInfoActivity : BaseActivity(), ShowUserView {
    private var outStock: OutStock? = null
    private var outTreasuryInfoBinding: ActivityOutTreasuryInfoBinding? = null
    override fun getLayoutId(): Int {
        return R.layout.activity_out_treasury_info
    }

    override fun initData() {
        titleCenterText.text = "出库详情"
        commonLeftLinearLayout.setOnClickListener { finish() }
        outStock = intent.getSerializableExtra("outStock") as OutStock
        outTreasuryInfoBinding = viewDataBinding as ActivityOutTreasuryInfoBinding
        outTreasuryInfoBinding?.handlerClick = this

        when (outStock!!.Status) {
            "1", "2" -> outTraceOrderState.text = "未结单"
            "3" -> outTraceOrderState.text = "已结单"
            "4" -> outTraceOrderState.text = "已收货"
        }
        HttpServer(this).outStockInfo(outStock!!.OutStockID, this)
    }

    override fun toMainActivity(what: Int, data: Any) {
        when (what) {
            35 -> {
                try {
                    val resultData = data as ResultBean<OutStockInfo>
                    if (resultData.State == "1") {
                        outTreasuryInfoBinding?.outStockInfo = resultData.ResultData
                    } else {
                        toast(resultData.Message)
                    }
                } catch (e: Exception) {
                    e.printStackTrace()
                }
            }
        }
    }

    fun orderInfoHandlerClick(view: View) {
        when (view.id) {
            R.id.orderInfoNext -> {
                val intent = Intent(this, OutgoingListActivity::class.java)
                intent.putExtra("outID", outStock!!.OutStockID)
                startActivity(intent)
            }
        }
    }
}
